home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkmid / alsaout.h next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  6.3 KB  |  232 lines

  1. /*  alsaout.cc   - class AlsaOut which represents an alsa client/port pair
  2.     This file is part of LibKMid 0.9.5
  3.     Copyright (C) 1997,98,99,2000  Antonio Larrosa Jimenez
  4.     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.     Boston, MA 02110-1301, USA.
  20.  
  21.     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
  22.  
  23. ***************************************************************************/
  24. #ifndef _ALSAOUT_H
  25. #define _ALSAOUT_H
  26.  
  27. #include <libkmid/midiout.h>
  28.  
  29. struct snd_seq_event;
  30. typedef struct snd_seq_event snd_seq_event_t;
  31.  
  32. /**
  33.  * @short Sends MIDI events to a MIDI devices using ALSA
  34.  * @version 0.9.5 17/01/2000
  35.  * @author Antonio Larrosa Jimenez <larrosa@kde.org>
  36.  */
  37. class AlsaOut : public MidiOut
  38. {
  39.   friend class DeviceManager;
  40.  
  41.   protected:
  42.  
  43. /**
  44.  * @internal
  45.  * Total number of devices.
  46.  */
  47.   int ndevs;
  48.  
  49. /**
  50.  * @internal
  51.  * Total number of midi ports
  52.  */
  53.   int nmidiports;
  54.  
  55.   double count;
  56.   double lastcount;
  57.   double lasttime;
  58.   double begintime;
  59.   int m_rate;
  60.  
  61. /**
  62.  * @internal
  63.  * A "constant" used to convert from milliseconds to the computer rate
  64.  */
  65.   double convertrate;
  66.  
  67.   long int time;
  68.  
  69.   virtual void seqbuf_dump (void);
  70.   virtual void seqbuf_clean(void);
  71.   void eventInit(snd_seq_event_t *ev);
  72.   void eventSend(snd_seq_event_t *ep);
  73.   void timerEventSend(int type);
  74.  
  75.   public:
  76.  
  77.   /**
  78.    * Constructor. After constructing a MidiOut device, you must open it
  79.    * (using openDev() ). Additionally you may want to initialize it
  80.    * (with initDev() ),
  81.    */
  82.   AlsaOut(int d, int client=64, int port=0, const char *cname="", const char *pname="");
  83.  
  84.   /**
  85.    * Destructor. It doesn't matter if you close the device ( closeDev() )
  86.    * before you destruct the object because in other case, it will be closed
  87.    * here.
  88.    */
  89.   virtual ~AlsaOut();
  90.  
  91.   /**
  92.    * Opens the device. This is generally called from DeviceManager , so you
  93.    * shouldn't call this yourself (except if you created the MidiOut object
  94.    * yourself.
  95.    * @param sqfd a file descriptor of /dev/sequencer
  96.    * @see closeDev
  97.    * @see initDev
  98.    */
  99.   virtual void openDev    (int sqfd);
  100.  
  101.   /**
  102.    * Closes the device. It basically tells the device (the file descriptor)
  103.    * is going to be closed.
  104.    * @see openDev
  105.    */
  106.   virtual void closeDev    ();
  107.  
  108.   /**
  109.    * Initializes the device sending generic standard midi events and controllers,
  110.    * such as changing the patches of each channel to an Acoustic Piano (000),
  111.    * setting the volume to a normal value, etc.
  112.    */
  113.   virtual void initDev    ();
  114.  
  115.   /**
  116.    * @return the device type of the object. This is to identify the
  117.    * inherited class that a given object is polymorphed to.
  118.    * The returned value is one of these :
  119.    *
  120.    * @li KMID_EXTERNAL_MIDI if it's a MidiOut object
  121.    * @li KMID_SYNTH if it's a SynthOut object (as an AWE device)
  122.    * @li KMID_FM if it's a FMOut object
  123.    * @li KMID_GUS if it's a GUSOut object
  124.    *
  125.    * which are defined in midispec.h
  126.    *
  127.    * @see deviceName
  128.    */
  129.   int          deviceType () const { return devicetype; }
  130.  
  131.   /**
  132.    * Returns the name and type of this MIDI device.
  133.    * @see deviceType
  134.    */
  135.   virtual const char * deviceName (void) const;
  136.  
  137.   /**
  138.    * @internal
  139.    */
  140.   int  rate    (void) { return m_rate; }
  141.  
  142.   /**
  143.    * See DeviceManager::noteOn()
  144.    */
  145.   virtual void noteOn    ( uchar chn, uchar note, uchar vel );
  146.  
  147.   /**
  148.    * See DeviceManager::noteOff()
  149.    */
  150.   virtual void noteOff    ( uchar chn, uchar note, uchar vel );
  151.  
  152.   /**
  153.    * See DeviceManager::keyPressure()
  154.    */
  155.   virtual void keyPressure    ( uchar chn, uchar note, uchar vel );
  156.  
  157.   /**
  158.    * See DeviceManager::chnPatchChange()
  159.    */
  160.   virtual void chnPatchChange    ( uchar chn, uchar patch );
  161.  
  162.   /**
  163.    * See DeviceManager::chnPressure()
  164.    */
  165.   virtual void chnPressure    ( uchar chn, uchar vel );
  166.  
  167.   /**
  168.    * See DeviceManager::chnPitchBender()
  169.    */
  170.   virtual void chnPitchBender    ( uchar chn, uchar lsb,  uchar msb );
  171.  
  172.   /**
  173.    * See DeviceManager::chnController()
  174.    */
  175.   virtual void chnController    ( uchar chn, uchar ctl , uchar v );
  176.  
  177.   /**
  178.    * See DeviceManager::sysex()
  179.    */
  180.   virtual void sysex        ( uchar *data,ulong size);
  181.  
  182.   /**
  183.    * Mutes all notes being played on a given channel.
  184.    */
  185.   virtual void channelSilence    ( uchar chn );
  186.  
  187.   /**
  188.    * Mute or "unmute" a given channel .
  189.    * @param chn channel to work on
  190.    * @param b if true, the device will ignore subsequent notes played on the chn
  191.    * channel, and mute all notes being played on it. If b is false, the channel
  192.    * is back to work.
  193.    */
  194.   virtual void channelMute    ( uchar chn, int b );
  195.  
  196.   /**
  197.    * Change all channel volume events multiplying it by this percentage correction
  198.    * Instead of forcing a channel to a fixed volume, this method allows to
  199.    * music to fade out even when it was being played softly.
  200.    * @param volper is an integer value, where 0 is quiet, 100 is used to send
  201.    * an unmodified value, 200 play music twice louder than it should, etc.
  202.    */
  203.   virtual void setVolumePercentage ( int volper )
  204.   { volumepercentage = volper; }
  205.  
  206.   /**
  207.    * Returns true if everything's ok and false if there has been any problem
  208.    */
  209.   int ok (void)
  210.   { if (seqfd<0) return 0;
  211.     return (_ok>0);
  212.   }
  213.  
  214.   virtual void wait        (double ticks);
  215.   virtual void tmrSetTempo (int v);
  216.   virtual void tmrStart    (int tpcn);
  217.   virtual void tmrStart    () { tmrStart(-1); }
  218.   virtual void tmrStop     ();
  219.   virtual void tmrContinue ();
  220.   /**
  221.    * @internal
  222.    * If i==1 syncronizes by cleaning the buffer instead of sending it (in fact,
  223.    * this is what synchronizing really means :-) )
  224.    */
  225.   void sync        (int i=0);
  226.  
  227.   class AlsaOutPrivate;
  228.   AlsaOutPrivate *di;
  229. };
  230.  
  231. #endif // _ALSAOUT_H
  232.